package org.example.xml;

import org.example.builder.BaseBuilder;
import org.example.config.Configuration;
import org.example.mapping.BoundSql;
import org.example.mapping.SqlSource;
import org.example.mapping.StaticSqlSource;
import org.example.parse.ParameterMappingTokenHandler;

import java.util.Map;

public class SqlSourceBuilder extends BaseBuilder {
    public SqlSourceBuilder(Configuration configuration){
        super(configuration);
    }

    public SqlSource parse(String originalSql, Class<?> parameterType) {
        ParameterMappingTokenHandler handler = new ParameterMappingTokenHandler(configuration,parameterType);
        GenericTokenParser parser = new GenericTokenParser("#{", "}", handler);
        String sql = parser.parse(originalSql);
        return new StaticSqlSource(configuration, sql, handler.getParameterMappings());
    }
}